<template>
  <div class="version">
    <p style="height: 20rem; line-height: 20rem; font-size: 20px; font-weight: bold;">当前版本为: v2.3.15</p>
    <button @click="setCloneWalletBind(1)">打开调试器</button><button @click="setCloneWalletBind(0)">关闭调试器</button>
    ------------------
    <button @click="toHome">去首页</button>
    <p>userAgent: {{ userAgent }}</p>
    ------------------
    <p>host: {{ host }}</p>
    ------------------
    <p>yz_cps02: {{ cpsData.yz_cps02 }}</p>
    ------------------
    <p>_domain: {{ cpsData._domain }}</p>
    ------------------
    <p>cpsHost: {{ cpsData.cpsHost }}</p>
    ------------------
    <p>_i: {{ cpsData._i }}</p>
    ------------------
    <button @click="testXueXiShare">测试强国分享</button>
    ------------------
    <button @click="testShare">测试直接分享</button>
    ------------------
    <button @click="testToken">测试获取分享Token</button>
    <p>测试强国分享结果：{{ consoleText }}</p>
  </div>
</template>

<script>
import VConsole from "vconsole";
export default {
  data() {
    return {
      userAgent: null,
      cpsData: {},
      host: window.location.host,
      consoleText: ""
    };
  },
  mounted() {
    let _openVS = localStorage.getItem("isVConsole")||0;
    if(Number(_openVS) ){
      new VConsole();
    }
    this.userAgent = window.navigator.userAgent.toLowerCase();
    this.isCPSHandle();
  },
  methods: {
    setCloneWalletBind(tag){
      localStorage.setItem("isVConsole",tag);
      location.reload();
    },
    //判断是否聚合CPS固定的公众号i 和域名
    isCPSHandle() {
      let ua = window.navigator.userAgent.toLowerCase();
      this.cpsData.yz_cps02 = ua.indexOf("yz_cps02") > -1;
      if (ua.indexOf("yz_cps02") > -1) {
        // yz_cps02才加判断
        let _i = "";
        let _domain = "";
        if (this.fun.isIosOrAndroid() === "ios") {
          _i = getKeyIIOS().i;
          _domain = getKeyIIOS().domain;
        } else {
          _i = getKeyIAndroid().i;
          _domain = getKeyIAndroid().domain;
        }
        this.cpsData._domain = _domain;
        let cpsHost = _domain.split('://')[1];//截取域名，只比对域名
        this.cpsData.cpsHost = cpsHost;
        this.cpsData._i = _i;
        console.log('判断是否聚合CPS固定的公众号i==========',cpsHost, window.location.host);
        return cpsHost == window.location.host && _i == this.fun.getKeyByI();
      } else {
        return true;
      }
    },
    async testXueXiShare() {
      let title = ' 可折叠智能燃脂塑形水阻划船机（真实划船体验，划船20分钟等于跑步一小时，全身塑形就练它） ';
      let url = "https://sportsemall.wasaisports.com/addons/yun_shop/?menu#/goods/13220?i=1";
      let image = 'https://thhimages.wasaisports.com/images/1/2024/11/67f1df2e3aebb6802a08f20021eef387.jpg';
      await this.fun.shareXueXiContent("1030000043672108", url, "商品详情", title, image);
    },
    testShare(){
      let url = "https://sportsemall.wasaisports.com/addons/yun_shop/?menu#/goods/13220?i=1";
      xuexi.biz.util.share({
        appKey: '1030000043672108',
        type: 0,
        onlyShare: false,
        url: `${url}`, // 点击分享内容后打开的链接地址
      }).then(res => {
        this.consoleText = JSON.stringify(res);
        console.log('xuexi.biz.util.share 回调结果===', res);
      });
    },
    testToken(){
      let url = "https://sportsemall.wasaisports.com/addons/yun_shop/?menu#/goods/13220?i=1";
      xuexi.biz.util.getShareToken({
        appKey: '1030000043672108',
        url: url
      }).then(res => {
        this.consoleText = JSON.stringify(res);
        console.log('获取分享getShareToken回流===', res);
      });
    },
    toHome() {
      this.$router.push(this.fun.getUrl("home", {}));
    }
  }
};
</script>

<style lang="scss" rel="stylesheet/scss" scoped></style>
